﻿using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace ApplLogic.ApplClasses
{
    [Serializable]
    public enum eResult
    {
        NONE,
        BYMANAGER,
        FIRST,
        SECOND,
        THIRD
    }

    [Serializable]
    public class ApplSingleResult
    {
        private ApplWorker m_ApplWorker;
        private ApplShift m_ApplShift;
        private eResult m_Step;

        public ApplWorker ApplWorker
        {
            get { return m_ApplWorker; }
            set { m_ApplWorker = value; }
        }

        public ApplShift ApplShift
        {
            get { return m_ApplShift; }
            set { m_ApplShift = value; }
        }

        public eResult Step
        {
            get { return m_Step; }
            set { m_Step = value; }
        }

        public static string ConvertEnumTypeToString(eResult type)
        {
            string asString = string.Empty;
            switch (type)
            {
                case eResult.NONE:
                    asString = "NONE";
                    break;
                case eResult.FIRST:
                    asString = "FIRST";
                    break;
                case eResult.SECOND:
                    asString = "SECOND";
                    break;
                case eResult.THIRD:
                    asString = "THIRD";
                    break;
                case eResult.BYMANAGER:
                    asString = "BY MANAGER";
                    break;
            }
            return asString;
        }

        public static eResult ConvertStringToEnum(string stringType)
        {
            eResult type = eResult.NONE;
            switch (stringType)
            {
                case "FIRST":
                    type = eResult.FIRST;
                    break;
                case "SECOND":
                    type = eResult.SECOND;
                    break;
                case "THIRD":
                    type = eResult.THIRD;
                    break;
                case "BY MANAGER":
                    type = eResult.BYMANAGER;
                    break;
                default:
                    break;
            }
            return type;
        }

        public ApplSingleResult DeepClone()
        {
            MemoryStream ms = new MemoryStream();
            BinaryFormatter bf = new BinaryFormatter();
            bf.Serialize(ms, this);
            ms.Position = 0;
            ApplSingleResult obj = (ApplSingleResult)bf.Deserialize(ms);
            ms.Close();
            return obj;
        }

        public override string ToString()
        {
            return string.Format("\n WorkerFullName: {0}\n ShiftName {1}\n Type: {2}\n",
                                 m_ApplWorker.PersonalDetails.FullName, m_ApplShift.Name,
                                 ConvertEnumTypeToString(m_Step));
        }

    }
}
